<template>
    <div class="root">
        <div class="button-group">
            <ButtonGroup>
                <Button :disabled="requestParams.fenxiang !== 1" @click="fengXiang">{{ $t('langObj.fenxiang') }}</Button>
                <Button :disabled="requestParams.qidong !== 1" @click="qiDong">{{ $t('langObj.xufei') }}</Button>
                <Button :disabled="requestParams.shifang !== 1" @click="saveISO = true">{{ $t('langObj.shifang') }}</Button>
                <Button type="warning" :disabled="requestParams.shanchu !== 1" @click="shanChu">{{ $t('langObj.shanchu') }}</Button>
            </ButtonGroup>
        </div>
        <iframe :src="url" frameborder="0" class="iframe"></iframe>
        <Modal
            v-model="saveISO"
            :mask-closable="false"
            width="360"
            title="释放机器">
            <div style="text-align:center;font-size:16px;font-weight:600;">是否保存镜像文件</div>
            <div slot="footer">
                <Button type="primary" @click="shiFang(false)">不保存</Button>
                <Button type="primary" @click="shiFang(true)">保存</Button>
            </div>
        </Modal>
    </div>
</template>

<script>
import { mapActions } from 'vuex';
export default {
    beforeRouteUpdate (to, from, next) {
        this.url = to.query.url ? decodeURI(to.query.url) : "";
        Object.keys(this.requestParams).forEach(ele => {
            this.requestParams[ele] = Number(to.query[ele]) || 0
        })
        next()
    },
    data(){
        return{
            url:decodeURI(this.$route.query.url) || "",
            requestParams:{
                taskId:Number(this.$route.query.taskId),
                qidong:Number(this.$route.query.qidong),
                fenxiang:Number(this.$route.query.fenxiang),
                shifang:Number(this.$route.query.shifang),
                shanchu:Number(this.$route.query.shanchu),
            },
            saveISO:false,
        }
    },
    methods:{
        ...mapActions(['XprojectShare','XprojectRelease','XprojectDelete']),
        fengXiang(){
            this.XprojectShare(this.requestParams.taskId).then(res => {
                this.$Message.success("分享成功")
            })
            .catch(err => {
                this.$Message.error(err.response.data.message)
            })
        },
        qiDong(){
            this.$router.push({path:`/order/${this.requestParams.taskId}/${2}/${1}`})
        },
        shiFang(params){
            let sendParmas = {
                commit:params,
                taskId:this.requestParams.taskId
            }
            this.XprojectRelease(sendParmas).then(res => {
                this.$Message.success("释放成功");
                this.$router.push({path:`/education/${this.$route.params.id}`})
            })
            .catch(err => {
                this.$Message.error(err.response.data.message)
            })
            this.saveISO = false;
        },
        shanChu(){
            this.XprojectDelete(this.requestParams.taskId).then(res => {
                this.$Message.success("删除成功");
                this.$router.push({path:`/education/${this.$route.params.id}`})
            })
            .catch(err => {
                this.$Message.error(err.response.data.message)
            })
        }
    },
}
</script>

<style lang="scss" scoped>
    .root{
        margin: 50px 0;
    }
    .button-group{
        margin-bottom:20px;
    }
    .iframe{
        width: 1000px;
        height: 500px;
    }
</style>